<?php

declare(strict_types=1);

namespace Fyfyu\Admin;

use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerInterface;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Fyfyu\Admin\Traits\Validator;
use Fyfyu\Admin\Traits\Layout;
use Fyfyu\Admin\Traits\ParseData;

abstract class Controller
{

    use Validator,Layout,ParseData;
    /**
     * @Inject
     * @var ContainerInterface
     */
    protected $container;

    /**
     * @Inject
     * @var RequestInterface
     */
    protected $request;

    /**
     * @Inject
     * @var ResponseInterface
     */
    protected $response;

    /**
     * Model
     */
    protected $model;

    /**
     * 页面标题
     * @var [type]
     */
    protected $title;
    /**
     * 分页条数
     * @var [type]
     */
    protected $limit = 15;


    /**
     * 列表
     * @GetMapping(path="")
     */
    public function index(){
        $this->grid->setModel($this->model);
        $this->grid();
        $grid = $this->grid->generate();
        $table = $this->table()->generate();
        $data = $this->getGridData($grid);
        $response = [
            'grid' => $grid,
            'table' => $table,
            'data' => $data
        ];
        return $response;
    }
    /**
     * 创建页
     * @GetMapping(path="create")
     */
    public function create(){
        $this->form->setModel($this->model);
        $this->form();
        return $this->form->generate();
    }
    /**
     * 保存
     * @PostMapping(path="create")
     */
    public function store(){
        return __FUNCTION__;
    }
    /**
     * 编辑操作
     * @GetMapping(path="{id:\d+}")
     */
    public function edit($id){
        return __FUNCTION__;
    }

    /**
     * 更新操作
     * @PutMapping(path="{id:\d+}")
     */
    public function update($id){
        return __FUNCTION__;
    }
    /**
     * 删除操作
     * @DeleteMapping(path="{id:[0-9\,]+}")
     * id1,id2,id3...
     */
    public function destroy($id){
        return __FUNCTION__;
    }

}
